<template>
  <div class="wrapper">
    <!-- <div style="padding-bottom: 10px;float: right;">
            <el-radio-group v-model="type" size="medium">
                <el-radio-button label="1">我是讲师</el-radio-button>
                <el-radio-button label="2">我是被培训的人</el-radio-button>
            </el-radio-group>
        </div> -->

    <!-- <el-tabs v-model="tabIndex" @tab-click="handleTabClick" class="tab" type="border-card">
            <el-tab-pane label="我是讲师" name="1"></el-tab-pane>
            <el-tab-pane label="我是被培训人" name="2"></el-tab-pane>
        </el-tabs> -->
    <div class="content-wrapper">
      <div class="tab-content">
        <div class="actions" style="margin-bottom: 10px">
          <div class="left">
            <!-- <template v-if="tabIndex === '1'">
                        <el-button type="primary" plain size="mini" @click="handleClickAdd">新增</el-button>
                        <el-button type="primary" plain size="mini" @click="">删除</el-button>
                    </template> -->
            <el-button
              type="primary"
              plain
              size="mini"
              @click="handleClickExport"
              >导出</el-button
            >
          </div>
          <div class="right">
            <el-pagination
              small
              background
              :current-page="paginations.pageIndex"
              :page-sizes="paginations.pageSizes"
              :page-size="paginations.pageSize"
              :layout="paginations.layout"
              :total="paginations.total"
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
            />
          </div>
        </div>
        <el-table
          ref="multipleTable"
          :data="tableData"
          border
          stripe
          align="center"
          @selection-change="handleSelectionChange"
          :max-height="maxheight"
        >
          <el-table-column type="selection" width="45"> </el-table-column>
          <el-table-column
            prop=""
            label="序号"
            width="50"
            type="index"
          ></el-table-column>
          <el-table-column prop="name" label="培训名称" width="180">
          </el-table-column>
          <el-table-column
            prop="plan_training_time"
            label="培训时间"
            width="180"
          >
            <template slot-scope="scope">
              <span v-time="scope.row.plan_training_time"></span>
            </template>
          </el-table-column>
          <el-table-column
            prop="plan_training_lecturer_name"
            label="培训讲师"
            width="180"
          >
          </el-table-column>
          <el-table-column
            prop="training_place"
            label="培训地点"
            min-width="180"
          >
          </el-table-column>
          <el-table-column v-if="tabIndex === '1'" prop="status" label="状态">
            <template slot-scope="scope">
              <el-tag
                size="mini"
                effect="dark"
                :type="
                  ['', '', 'success', 'warning', 'danger'][scope.row.status]
                "
              >
                {{ ["", "草稿", "未培训", "已培训", "作废"][scope.row.status] }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column
            v-if="tabIndex === '2'"
            prop="plan_training_user"
            label="参加状态"
            width="180"
          >
            <template slot-scope="scope">
              {{ ["未参加", "已参加"][scope.row.plan_training_user[0].status] }}
            </template>
          </el-table-column>
          <!-- <el-table-column prop="formwork_list" label="模板">
                <template slot-scope="scope">
                    <div v-for="(item, index) in scope.row.formwork_list" :key="index" class="text item">
                        <el-link :href="item.file_url" target="_blank">{{ item.file_name }}</el-link>
                    </div>
                </template>
            </el-table-column> -->
          <el-table-column
            prop=""
            fixed="right"
            align="center"
            label="操作"
            width="160"
          >
            <template slot-scope="scope">
              <el-button
                type="text"
                plain
                size="mini"
                @click="handleOperation(scope.row, 'edit')"
              >
                {{ tabIndex === "1" ? "编辑" : "参加培训" }}
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
import { trainingPlanMineList, trainingPlanListExport } from "@/api/qms.js";

export default {
  name: "refundReviewList",
  components: {},
  props: [],
  data() {
    return {
      maxheight: "auto",
      tableData: [],
      paginations: {
        pageIndex: 1, // 当前位于哪页
        pageSize: 20, // 1页显示多少条
        pageSizes: [10, 20, 50, 100], //每页显示多少条
        total: 200,
        layout: "total, sizes, prev, pager, next, jumper", // 翻页属性
      },
      checkedList: [],
      searchParams: {},
      mode: "",
      tabIndex: "1",
    };
  },
  mounted() {
    this.getDataList();
  },
  watch: {
    $route: {
      handler(newV, oldV) {
        if (this.$route.query.type == 0) {
          this.tabIndex = "0";
          this.handleTabClick();
        } else if (this.$route.query.type == 1) {
          this.tabIndex = "1";
          this.handleTabClick();
        }
      },
      immediate: true,
      deep: true,
    },
  },
  methods: {
    handleClickExport() {
      const tabParams = this.getTabParams();
      trainingPlanListExport({
        page: this.paginations.pageIndex,
        page_size: this.paginations.pageSize,
        ...this.searchParams,
        ...tabParams,
      }).then((res) => {
        this.reqUrl = "https://" + res.data.data;
        window.open(this.reqUrl);
      });
    },
    handleClickAdd() {
      this.mode = "add";
      this.$router.push({
        name: "train",
      });
    },
    handleOperation(row, mode) {
      this.$router.push({
        name: "train",
        query: {
          id: row.id,
          mode,
          origin: this.tabIndex === "2" ? "join" : "train",
        },
      });
    },
    handleClickOperation() {},
    handleTabClick() {
      this.getDataList();
    },

    handleSelectionChange(checked) {
      this.checkedList = checked.map((item) => item.id);
    },
    handleCloseDialog() {
      this.dialogVisible = false;
    },
    // 每页条数改变
    handleSizeChange(val) {
      this.paginations.pageSize = val;
      this.getDataList();
    },
    // 当前页改变
    handleCurrentChange(val) {
      this.paginations.pageIndex = val;
      this.getDataList();
    },
    getTabParams() {
      const { user_id } = this.$store.state.user || {};
      return {
        user_id: user_id * 1,
        status: [2, 3],
        user_type: this.tabIndex * 1,
      };
    },
    getDataList() {
      const tabParams = this.getTabParams();
      trainingPlanMineList({
        page: this.paginations.pageIndex,
        page_size: this.paginations.pageSize,
        ...this.searchParams,
        ...tabParams,
      }).then((res) => {
        this.tableData = res.data.list || [];
        if (this.tableData.length > 6) {
          //一排操作栏
          this.maxheight = document.documentElement.clientHeight - 245;
        } else {
          this.maxheight = "auto";
        }
        this.paginations.total = res.data.pagination.total;
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.wrapper {
  background-color: #fff;
  padding: 10px 15px;

  .orderHeader {
    margin-top: 5px;
    background-color: #fff;

    .orderSearch {
      form {
        ::v-deep .el-form-item__label {
          font-size: 14px;
        }

        .el-textarea {
          width: 135px;
        }
      }
    }
  }

  .actions {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    width: 100%;
    background-color: #fff;

    .el-button + .el-dropdown,
    .el-dropdown + .el-button {
      margin-left: 10px;
    }
  }

  .tab.el-tabs--border-card {
    border: none;
    box-shadow: none;

    .el-tabs__content {
      padding: 0;
      height: 40px;
    }
  }

  /deep/.tab.el-tabs--border-card > .el-tabs__content {
    padding: 0px;
  }

  .tab-content {
    // padding: 10px;
  }
}
</style>